package com.itheima.test;

import java.util.Random;

public class arraytest9 {
    public static void main(String[] args) {
        //定义一个数组，存1-5，打乱所有数据的顺讯

        int[] arr = {1,2,3,4,5};
        Random r = new Random();
        /*int randomIndex = r.nextInt(arr.length);
        System.out.println(arr[randomIndex]);*/

        for (int i = 0; i < arr.length; i++) {
            int randomIndex = r.nextInt(arr.length);
            int temp = arr[i];
            arr[i] = arr[randomIndex];
            arr[randomIndex] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
